#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2022-2-25 9:50
# @Author : huabao.tan
# @File : case_tas6.py
# @Software: PyCharm

import json
import requests
from work.t6.config import *
import time
from tool.excel.excel_tool import *

class Tas(CreatExcel):
    def __init__(self):
        CreatExcel.__init__(self)



    def dealStr(self, str, type = None):
        '''
        :param str:
        :param type:
        :return:
        '''
        size = len(str)
        a = 5-size
        if type == None:
            str +=  "　" * a
        else:
            str += " " * a
        return str


    def response(self):
        response = requests.post(url=URL, headers=HEADERS, data=json.dumps(DATA)).json()
        return response

    def creat_excel(self):
        res = self.response()['response']['pageData']['results']
        list = ['userName', 'taskUserId', 'passCode', 'taskId', 'time', 'userId']
        b = 0
        for a in list:
            b += 1
            self.sheet_row_col_value(0, 1, b, a)
        row = 1
        for a in res:
            row += 1
            col = 0
            now_time = time.localtime(a['createTime'] / 1000)  # python 时间戳格式只支持10位数，超出就除以至10位数
            dt = time.strftime("%Y-%m-%d %H:%M:%S", now_time)
            print('userName: %s' % self.dealStr(str(a['userName'])), 'taskUserId: %s' % self.dealStr(str(a['taskUserId'])),
                  'passCode: %s' % self.dealStr(str(a['passCode'])), 'taskId: %s' % self.dealStr(str(a['taskId'])),
                  '时间：%s' % self.dealStr(str(dt)), 'userId:%s' % a['userId'])
            list1 = [a['userName'], a['taskUserId'], a['passCode'], a['taskId'], str(dt), a['userId']]
            for d in list1:
                col += 1
                self.sheet_row_col_value(0, row, col, d)
        print('该项目下共有：%s人' % len(res))

if __name__ == '__main__':
    t = Tas()
    t.creat_excel()